<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-icon">
        <img src="@/assets/logo.png" alt="" />
      </div>
      <el-form
        ref="form"
        v-model="loginForm"
        :rules="loginFormRule"
        label-width="80px"
      >
        <el-form-item prop="username" required>
          <!-- <i class="iconfont iconpeoplecopy3"></i> -->
          <el-input prefix-icon="iconfont iconlock" v-model="loginForm.username" class="input_item"></el-input>
        </el-form-item>
        <el-form-item prop="password" required>
          <!-- <i class="iconfont iconlock"></i> -->
          <el-input v-model="loginForm.password" class="input_item"></el-input>
        </el-form-item>
        <el-form-item class="login-btn">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button @click="resetForm()">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginFormRule: {
        username: [
          {
            min: 3,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur'
          }
        ],
        password: [
          {
            min: 6,
            max: 15,
            message: '长度在 6 到 15 个字符',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    resetForm() {
      this.$refs.form.resetFields()
    },
    login() {
      this.$http.post('/login', this.loginForm).then((res) => {
        console.log(res)
      })
    }
  },
  watch: {
    username(oldValue, newValue) {
      console.log(oldValue, newValue)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.login-container {
  height: 100%;
  background-color: #2b4b6b;
  .login-box {
    position: absolute;
    height: 300px;
    width: 450px;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    background-color: #fff;
    border-radius: 3px;

    .login-icon {
      height: 110px;
      width: 110px;
      background-color: #fff;
      margin-left: 175px;
      margin-top: -50px;
      border-radius: 50%;
      img {
        width: 100px;
        margin: 5px 0 0 5px;
        border-radius: 50%;
        background-color: #f9f9f9;
      }
    }
    .el-form {
      margin: 30px 50px 0 0;
      .login-btn {
        float: right;
      }
    }
  }
}

.iconpeoplecopy3 {
  position: absolute;
  z-index: 2;
  font-size: 20px;
  left: -25px;
}
.iconlock {
  position: absolute;
  font-size: 25px;
  z-index: 2;
  left: -27px;
}
</style>
